import 'Cart.dart';
import 'User.dart';

class JsonConvert {
  /// 把 Map 转成自定义的实体类
  static T? fromJsonAsT<T>(Map<String, dynamic> json) {
    switch (T.toString()) {
      case 'User':
        return User.fromJson(json) as T;
      case 'Cart':
        return Cart.fromJson(json) as T;
    }
    return json as dynamic;
  }

  /// 把数据转成基础类型
  static T? asT<T>(dynamic value) {
    if (value is T) {
      return value;
    }
    return null;
  }
}
